package com.example.project_board.controller;


import com.example.project_board.mapper.SuggestionMapper;
import com.example.project_board.model.Suggestion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@RestController
public class SendSuggestion {
    @Autowired
    SuggestionMapper suggestionMapper;
    @RequestMapping("/sug")
    @ResponseBody
    public Object insertsug(@RequestParam Map<String, Object> params){
        String userid = (String) params.get("userid");
        String talk = (String) params.get("talk");
        String k = suggestionMapper.confirmUser(userid);
        if (k == null || k.equals("")){
            return new ModelAndView("suggestion");
        }else {
            Suggestion suggestion = new Suggestion();
            suggestion.setUserid(userid);
            suggestion.setTalk(talk);
            suggestionMapper.insertSuggestion(suggestion);
            return new ModelAndView("userindex");
        }
    }
}